package calendario_teste;

import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class DayCanvas extends Canvas{
	
	private Color colorLines = Color.lightGray;
	private Color colorTopRect = new Color(179, 204, 220);
	private Color colorBackground = Color.white;
	protected int k_width=140*7;
	protected int k_height=90*5;
	protected int k_height_topRect = 25;
	protected String day ;//= 
	protected Dimension d ;
	
	protected Date time = new Date();
	protected int tempo = 1000*60*60*13; //8h da manha = 1000ms*60s*60m*5
	protected String s;
	protected Format formatter;
	protected int incTime = 1000*60*30;//meia hora
	
	public DayCanvas(){//(String day){ //
		day="Friday 11/03";
		int heightTotalCanvas = 800;
		d = new Dimension(k_width, heightTotalCanvas);
		time.setTime(tempo);
		formatter = new SimpleDateFormat("hh:mm a");
		setBackground(colorBackground);
		setSize(d);

		
		
	}
	
	public void paint(Graphics g){
		Graphics2D g2=(Graphics2D) g;
		//drawTopRect(g2);
//		drawStringTop(g2);
		
		for(int i=0;i<24;i++){ //de 8 da manha, ateh 8 da noite
			drawLines(g2, (i+1)*30);
			drawTime(g2, ((i+1)*30)-2, i);
		}
	}
	
	public void drawLines(Graphics2D g2, int height){
		g2.setColor(colorLines);
		g2.drawLine(5, height, k_width-5, height);
	}
	
	public void drawTime(Graphics2D g2, int height, int inc){
		time.setTime(tempo+incTime*inc);
		g2.setColor(colorLines);
		s = formatter.format(time);
		g2.drawString(s, 5, height);
	}
	
//	public void drawTopRect(Graphics2D g2){
//		g2.setColor(colorTopRect);
//		g2.fillRect(0, 0, k_width, k_height_topRect);
//	}
	
//	public void drawStringTop(Graphics2D g2){
//		g2.setColor(Color.black);
//		g2.drawString(day, (k_width-80)/2, 17);
//	}
//	
	public void setDay(String day){
		this.day=day;
	}
	public String getDay(){
		return day;
	}
	
	public JComponent getPanelDay(){
		JPanel panel = new JPanel();
		TopCanvas top = new TopCanvas(day);
		top.setWidth(k_width);
		panel.setLayout(new BorderLayout());
		panel.add(this, BorderLayout.CENTER);
		panel.add(top, BorderLayout.NORTH);
	
		return panel;
	}
	
	
}
